﻿using System;
using System.Diagnostics;
using Microsoft.VisualStudio.Modeling.Shell;
//using Microsoft.VisualStudio.EnterpriseTools.ClassDesigner;
//using Microsoft.VisualStudio.EnterpriseTools.ClassDesigner.PresentationModel;

namespace ModelingAddIns
{
    /// <summary>
    /// Context provider for OrmDesigner Contexts contexts.
    /// </summary>
    [Feature(Name = "Orm Designer Contexts Provider", Container = typeof(GlobalContext),
        Description = "This feature watches active orm diagrams and instantiates orm designer and diagram contexts as new diagrams are opened.")]
    public sealed class OrmDesignerContextProvider : DesignerContextProvider
    {
        /*protected override bool IsDocDataSupported(object docData)
        {
            //Debug.Assert(docData != null);
            ModelingDocData modelingDocData = docData as ModelingDocData;
            //return modelingDocData != null && modelingDocData.RootElement is ClassDiagram;
            return true;
        }*/

        protected override DesignerContext CreateDesignerContext()
        {
            IFeatureContext featureContext = this.ServiceProvider.GetService<IFeatureContext>();
            Debug.Assert(featureContext != null);
            if (featureContext != null)
            {
                return featureContext.CreateFeature<OrmDesignerContext>();
            }
            return null;
        }

        protected override DiagramContext CreateDiagramContext(object docData)
        {
            Debug.Assert(docData != null);
            return new OrmDiagramContext();
        }
    }

    /// <summary>
    /// Container for class designer features.
    /// </summary>
    [Feature(Name = "Orm Designer Contexts", Container = typeof(OrmDesignerContextProvider),
       Description = "A container for features which become enabled once a class diagram is opened.")]
    public sealed class OrmDesignerContext : DesignerContext
    {
    }

    /// <summary>
    /// Container for orm diagram features.
    /// </summary>
    //[CLSCompliant(false)]
    [Feature(Name = "Class Diagram Context", Container = typeof(OrmDesignerContextProvider),
       Description = "A container for per-class-diagram features. An instance of this feature is created for each class diagram opened.")]
    public sealed class OrmDiagramContext : DiagramContext
    {
    }
}